import { Injectable } from '@angular/core';
import {RequestUtil} from "../../../util/request-util";
import {Observable} from "rxjs";
import {MsgResult} from "../../../models/msg-result";
import {API} from "../../../constants/constants";

@Injectable()
export class GovinfosService {

  //声明实例
  // govInfo :GovInfo;

  constructor(
    private requestUtil :RequestUtil
  ) { }

  //政府无参查询
  getGovInfos():Observable<MsgResult>{
  return this.requestUtil.get(API.getGovInfos);
  }

  //添加政府信息
  insertGovInfo(govInfo):Observable<MsgResult>{
    let params="name="+govInfo.name+"&phone="+govInfo.phone+"&regionCode="+govInfo.regionCode+"&remark="+
      govInfo.remark+"&isValid="+govInfo.isValid+"&isDisable="+govInfo.isDisable;
      return this.requestUtil.post(API.insertGovInfo,params);
  }

  //删除政府信息
  deleteGovInfo(id):Observable<MsgResult>{
    let params="id="+id;
    return this.requestUtil.get(API.deleteGovInfo,params);
  }

  //根据id查询
  getGovInfoById(id){
    let params="id="+id;
    return this.requestUtil.get(API.getGovInfoById,params);
  }

  //模糊查询
  getGovByFuzzy(searchValue){
    let params="searchValue="+searchValue
   return this.requestUtil.get(API.getGovByFuzzy,params);
  }

  //修改政府信息
  updateGovInfo(govInfo){
    let params="id="+govInfo.id+"&name="+govInfo.name+"&phone="+govInfo.phone+"&regionCode="+govInfo.regionCode+"&remark="+
      govInfo.remark+"&isValid="+govInfo.isValid+"&isDisable="+govInfo.isDisable;
    return this.requestUtil.post(API.updateGovInfo,params);
  }
//获取行政区划树
  getRetrieveRegionsTree(): Observable<MsgResult> {
    return this.requestUtil.get(API.getRetrieveRegionsTree);
  }
}
